﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


using DesignMode.AdapterPattern;
using DesignMode.BridgePattern;
using DesignMode.DecoratorPattern;
using DesignMode.CompositePattern;
using DesignMode.FacadePattern;
using DesignMode.FlyweightPattern;
using DesignMode.ProxyPattern;
using DesignMode.TemplateMethod;
using DesignMode.CommandPattern;
using DesignMode.IteratorPattern;
using DesignMode.ObserverPattern;
using DesignMode.MediatorPattern;
//using DesignMode.StatePattern;
//using DesignMode.StragetyPattern;
//using DesignMode.ChainofResponsibilityPattern;
//using DesignMode.VistorPattern;
using DesignMode.MementoPattern;


namespace DesignMode
{
    class Program
    {
        static void Main(string[] args)
        {
            // 备忘录
            Originator o = new Originator();
            o.State = "On";
            Caretaker c = new Caretaker();
            c.Memento = o.CreateMemento();

            o.State = "Off";
            o.SetMemento(c.Memento);

            ////访问者
            //ObjectStructure objectStructure = new ObjectStructure();
            //foreach(Element e in objectStructure.Elements)
            //{
            //    e.Accept(new ConcreteVistor());
            //}

            ////责任链
            //PurchaseRequest requestTelphone = new PurchaseRequest(4000.0, "Telphone");
            //PurchaseRequest requestSoftware = new PurchaseRequest(10000.0, "Visual Studio");
            //PurchaseRequest requestComputers = new PurchaseRequest(40000.0, "Computers");

            //Approver manager = new Manager("LearningHard");
            //Approver Vp = new VicePresident("Tony");
            //Approver Pre = new President("BossTom");
            //manager.NextApprover = Vp;
            //Vp.NextApprover = Pre;

            //manager.ProcessRequest(requestTelphone);
            //manager.ProcessRequest(requestSoftware);
            //manager.ProcessRequest(requestComputers);
            //Console.ReadLine();

            //策略模式
            //Context context = new Context(new ConcreteStrategyA());
            //context.Print();
            //context = new Context(new ConcreteStrategyB());
            //context.Print();


            //状态模式
            //Context context = new Context(new ConcreteStateA());
            //context.Request();
            //context.Request();
            //context.Request();

            //// 中介者
            //AbstractCardPartner A = new ParterA();
            //AbstractCardPartner B = new ParterB();
            //// 初始钱
            //A.MoneyCount = 20;
            //B.MoneyCount = 20;
            //AbstractMediator mediator = new MediatorPater(A, B);
            //A.ChangeCount(5, mediator);
            //Console.WriteLine("A 现在的钱是：{0}", A.MoneyCount);// 应该是25
            //Console.WriteLine("B 现在的钱是：{0}", B.MoneyCount); // 应该是15
            //B.ChangeCount(5, mediator);
            //Console.WriteLine("A 现在的钱是：{0}", A.MoneyCount);// 应该是25
            //Console.WriteLine("B 现在的钱是：{0}", B.MoneyCount); // 应该是15

            //// 观察者
            //ConcreteSubject s = new ConcreteSubject();
            //s.Attach(new ConcreteObserver(s, "X"));
            //s.Attach(new ConcreteObserver(s, "Y"));
            //s.Attach(new ConcreteObserver(s, "Z"));
            //s.SubjectState = "Hello World";
            //s.Notify();

            // 迭代器模式
            //ConcreteAggregate a = new ConcreteAggregate();
            //a[0] = "Item A";
            //a[1] = "Item B";
            //a[2] = "Item C";
            //a[3] = "Item D";

            //ConcreteIterator i = new ConcreteIterator(a);
            //Console.WriteLine("Iterating over collection:");
            //object item = i.First();
            //while(item != null)
            //{
            //    Console.WriteLine(item);
            //    item = i.Next();
            //}


            ////命令
            //Receiver r = new Receiver();
            //Command c = new ConcreteCommand(r);
            //Invoke i = new Invoke(c);
            //i.ExecuteCommand();

            //// 代理模式
            //Proxy p = new Proxy();
            //p.Request();
            ////享元模式
            //// 定义外部状态，例如字母的位置等信息
            //int externalstate = 10;
            //// 初始化享元工厂
            //FlyweightFactory factory = new FlyweightFactory();
            //// 判断是否已经创建了字母C
            //Flyweight fc = factory.GetFlyweight("C");
            //if (fc != null)
            //{
            //    fc.Operation(--externalstate);
            //}
            //// 判断是否已经创建了字母D
            //Flyweight fd = factory.GetFlyweight("D");
            //if (fd != null)
            //{
            //    fd.Operation(--externalstate);
            //}
            //else
            //{
            //    Console.WriteLine("驻留池中不存在字符串D");
            //    // 这时候就需要创建一个对象并放入驻留池中
            //    ConcreteFlyweight d = new ConcreteFlyweight("D");
            //    factory.flyweights.Add("D", d);
            //}

            ////外观模式
            //Facade facade = new Facade();
            //facade.Init();

            //组合模式
            //Composite root = new Composite("root");
            //root.Add(new Leaf("Leaf A"));
            //root.Add(new Leaf("Leaf B"));

            //Composite comp = new Composite("Composite X");
            //comp.Add(new Leaf("Leaf XA"));
            //comp.Add(new Leaf("Leaf XB"));
            //root.Add(comp);

            //Leaf leaf = new Leaf("Leaf D");
            //root.Add(leaf);
            //root.Remove(leaf);
            //root.Display(1);

            //装饰者
            //Component c = new ConcreteComponent();
            //Decorator d1 = new ConcreteDecoratorA();
            //d1.SetComponent(c);
            //d1.Operation();
            //Decorator d2 = new ConcreteDecoratorB();
            //d2.SetComponent(c);
            //d2.Operation();

            ////桥接模式
            //Abstraction abstraction = new RefinedAbstraction();
            //abstraction.Implementor = new ConcreteImplementorA();
            //abstraction.Operation();
            //abstraction.Implementor = new ConcreteImplementorB();
            //abstraction.Operation();

            ////适配器
            //ITarget t = new Adapter();
            //t.Request();
        }
    }
}
